Source for file SC_CartSession.php
Documentation is available at SC_CartSession.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* @author LOCKON CO.,LTD.
* @version $Id: SC_CartSession.php 21296 2011-10-22 14:44:09Z Seasoft $
if (!isset ($_SESSION[$cartKey])) {
$_SESSION[$cartKey] = array();
$this->key_tmp = "savecart_" . $key_tmp;
// すでに情報がなければ現状のカート情報を記録しておく
foreach($_SESSION as $k => $val) {
$ret = isset ($this->cartSession[$productTypeId]['cancel_purchase'])
? $this->cartSession[$productTypeId]['cancel_purchase'] : "";
$this->cartSession[$productTypeId]['cancel_purchase'] = false;
$max = $this->getMax($productTypeId);
for($i = 1; $i <= $max; $i++ ) {
!= $_SESSION[$this->key_tmp][$i]['quantity']) {
!= $_SESSION[$this->key_tmp][$i]['id']) {
$this->cartSession[$productTypeId][$key]['cancel_purchase'] = true;
$this->cartSession[$productTypeId]['cancel_purchase'] = false;
return $this->cartSession[$productTypeId]['cancel_purchase'];
foreach($this->cartSession[$productTypeId] as $key => $val){
$arrRet[] = $this->cartSession[$productTypeId][$key]['cart_no'];
* XXX 実際には、「商品」ではなく、「カートの明細行(≒商品規格)」のような気がします。
* @return string 商品ごとの合計価格(税込み)
* @deprecated SC_CartSession::getCartList() を使用してください
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
&& $this->cartSession[$productTypeId][$i]['id'] == $id) {
$price = $this->cartSession[$productTypeId][$i]['price'];
$quantity = $this->cartSession[$productTypeId][$i]['quantity'];
$incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
$total = $incTax * $quantity;
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
&& $this->cartSession[$productTypeId][$i]['id'] == $id) {
function getMax($productTypeId) {
foreach($this->cartSession[$productTypeId] as $key => $val) {
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
$total+= $this->cartSession[$productTypeId][$i]['quantity'];
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
if (!isset ($this->cartSession[$productTypeId][$i]['price'])) {
$price = $this->cartSession[$productTypeId][$i]['price'];
if (!isset ($this->cartSession[$productTypeId][$i]['quantity'])) {
$this->cartSession[$productTypeId][$i]['quantity'] = "";
$quantity = $this->cartSession[$productTypeId][$i]['quantity'];
$incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
$total+= ($incTax * $quantity);
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
$price = $this->cartSession[$productTypeId][$i]['price'];
$quantity = $this->cartSession[$productTypeId][$i]['quantity'];
$tax = SC_Helper_DB_Ex::sfTax($price);
$total+= ($tax * $quantity);
if (USE_POINT !== false) {
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
$price = $this->cartSession[$productTypeId][$i]['price'];
$quantity = $this->cartSession[$productTypeId][$i]['quantity'];
if (!isset ($this->cartSession[$productTypeId][$i]['point_rate'])) {
$this->cartSession[$productTypeId][$i]['point_rate'] = "";
$point_rate = $this->cartSession[$productTypeId][$i]['point_rate'];
if (!isset ($this->cartSession[$productTypeId][$i]['id'][0])) {
$point = SC_Utils_Ex::sfPrePoint($price, $point_rate);
$total+= ($point * $quantity);
function addProduct($product_class_id, $quantity) {
$objProduct = new SC_Product_Ex();
$arrProduct = $objProduct->getProductsClass($product_class_id);
$productTypeId = $arrProduct['product_type_id'];
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
if($this->cartSession[$productTypeId][$i]['id'] == $product_class_id) {
$val = $this->cartSession[$productTypeId][$i]['quantity'] + $quantity;
$this->cartSession[$productTypeId][$i]['quantity'] += $quantity;
$this->cartSession[$productTypeId][$max+ 1]['id'] = $product_class_id;
$this->cartSession[$productTypeId][$max+ 1]['quantity'] = $quantity;
function setPrevURL($url, $excludePaths = array()) {
foreach($arrExclude as $val) {
// 除外ページでない場合は、前頁として記録する。
$_SESSION['prev_url'] = $url;
return isset ($_SESSION['prev_url']) ? $_SESSION['prev_url'] : "";
for($i = 0; $i < $max; $i++ ) {
if($this->cartSession[$productTypeId][$i][$keyname] == $val) {
function setValue($key, $val, $productTypeId) {
function getValue($key, $productTypeId) {
* productsClass項目から、不必要な項目を削除する。
$arrNecessaryItems = array(
'product_class_id' => true,
'main_list_image' => true,
'stock_unlimited' => true,
'classcategory_name1' => true,
'classcategory_name2' => true,
if (!isset ($arrNecessaryItems[$key])) {
unset ($arrProductsClass[$key]);
* @param integer $productTypeId 商品種別ID
* @return array カート内商品一覧の配列
$objProduct = new SC_Product_Ex();
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
if(isset ($this->cartSession[$productTypeId][$i]['cart_no'])
&& $this->cartSession[$productTypeId][$i]['cart_no'] != "") {
$this->cartSession[$productTypeId][$i]['productsClass']
= & $objProduct->getDetailAndProductsClass($this->cartSession[$productTypeId][$i]['id']);
$price = $this->cartSession[$productTypeId][$i]['productsClass']['price02'];
$this->cartSession[$productTypeId][$i]['price'] = $price;
$this->cartSession[$productTypeId][$i]['productsClass']['point_rate'];
$quantity = $this->cartSession[$productTypeId][$i]['quantity'];
$incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
$total = $incTax * $quantity;
$this->cartSession[$productTypeId][$i]['total_inctax'] = $total;
// セッション変数のデータ量を抑制するため、一部の商品情報を切り捨てる
// XXX 上で「常に取得」するのだから、丸ごと切り捨てて良さそうにも感じる。
* @return array すべてのカートの内容
foreach ($cartKeys as $key) {
$cartItem = & $cartItems[$itemKey];
$results[$key][$i] = & $cartItem;
* @deprected getAllProductClassID を使用して下さい
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
$arrRet[] = $this->cartSession[$productTypeId][$i]['id'][0];
* @param integer $productTypeId 商品種別ID
* @return array 商品規格ID の配列
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
$arrRet[] = $this->cartSession[$productTypeId][$i]['id'];
* 商品種別ID を指定して, カート内の商品をすべて削除する.
* @param integer $productTypeId 商品種別ID
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
$max = $this->getMax($productTypeId);
for($i = 0; $i <= $max; $i++ ) {
if($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
$quantity = $this->getQuantity($cart_no, $productTypeId);
if (strlen($quantity + 1) <= INT_LEN) {
$this->setQuantity($quantity + 1, $cart_no, $productTypeId);
$quantity = $this->getQuantity($cart_no, $productTypeId);
$this->setQuantity($quantity - 1, $cart_no, $productTypeId);
* カート番号と商品種別IDを指定して, 数量を取得する.
* @param integer $cart_no カート番号
* @param integer $productTypeId 商品種別ID
* @return integer 該当商品規格の数量
$max = $this->getMax($productTypeId);
for ($i = 0; $i <= $max; $i++ ) {
if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
return $this->cartSession[$productTypeId][$i]['quantity'];
* カート番号と商品種別IDを指定して, 数量を設定する.
* @param integer $quantity 設定する数量
* @param integer $cart_no カート番号
* @param integer $productTypeId 商品種別ID
function setQuantity($quantity, $cart_no, $productTypeId) {
$max = $this->getMax($productTypeId);
for ($i = 0; $i <= $max; $i++ ) {
if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
$this->cartSession[$productTypeId][$i]['quantity'] = $quantity;
* カート番号と商品種別IDを指定して, 商品規格IDを取得する.
* @param integer $cart_no カート番号
* @param integer $productTypeId 商品種別ID
for ($i = 0; $i <= $max; $i++ ) {
if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
* エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
* 1. 商品種別に関連づけられた配送業者の存在チェック
* @param string $key 商品種別ID
* @return string エラーが発生した場合はエラーメッセージ
$objProduct = new SC_Product_Ex();
$product = & $item['productsClass'];
if (SC_Utils_Ex::isBlank($product)) {
$this->delProduct($item['cart_no'], $productTypeId);
$tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
$arrDeliv = SC_Helper_Purchase_Ex::getDeliv($productTypeId);
if (SC_Utils_Ex::isBlank($arrDeliv)) {
$tpl_message .= "※「" . $product['name'] . "」はまだ配送の準備ができておりません。恐れ入りますがお問い合わせページよりお問い合わせください。\n";
$this->delProduct($item['cart_no'], $productTypeId);
$limit = $objProduct->getBuyLimit($product);
if (!is_null($limit) && $item['quantity'] > $limit) {
$this->setProductValue($item['id'], 'total_inctax', SC_Helper_DB_Ex::sfCalcIncTax($item['price']) * $limit, $productTypeId);
$tpl_message .= "※「" . $product['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n";
$this->delProduct($item['cart_no'], $productTypeId);
$tpl_message .= "※「" . $product['name'] . "」は売り切れました。\n";
* @param integer $productTypeId 商品種別ID
* @return boolean 送料無料の場合 true
$objDb = new SC_Helper_DB_Ex();
if (DELIV_FREE_AMOUNT > 0) {
if($total_quantity >= DELIV_FREE_AMOUNT) {
$arrInfo = $objDb->sfGetBasisData();
if ($arrInfo['free_rule'] > 0) {
if($subtotal >= $arrInfo['free_rule']) {
* カートの内容を計算し, 下記のキーを保持する連想配列を返す.
* - deliv_fee: カート内商品の合計送料
* - payment_total: お支払い合計
* @param integer $productTypeId 商品種別ID
* @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
* @param integer $use_point 今回使用ポイント
* @param integer|array$deliv_pref 配送先都道府県ID.
* @param integer $charge 手数料
* @param integer $discount 値引
* @param integer $deliv_id 配送業者ID
* @return array カートの計算結果の配列
function calculate($productTypeId, &$objCustomer, $use_point = 0,
$deliv_pref = "", $charge = 0, $discount = 0, $deliv_id = 0) {
$objDb = new SC_Helper_DB_Ex();
$results['deliv_fee'] = 0;
if (OPTION_PRODUCT_DELIV_FEE == 1) {
foreach ($cartItems as $item) {
$results['deliv_fee'] += $item['productsClass']['deliv_fee'] * $item['quantity'];
if (OPTION_DELIV_FEE == 1
&& !SC_Utils_Ex::isBlank($deliv_pref)
&& !SC_Utils_Ex::isBlank($deliv_id)) {
$results['deliv_fee'] += $objDb->sfGetDelivFee($deliv_pref, $deliv_id);
$results['deliv_fee'] = 0;
$results['total'] = $results['subtotal'];
$results['total'] += $results['deliv_fee'];
$results['total'] += $charge;
$results['total'] -= $discount;
$results['payment_total'] = $results['total'] - $use_point * POINT_VALUE;
if (USE_POINT !== false) {
$results['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($total_point,
if($objCustomer->isBirthMonth()) {
$results['birth_point'] = BIRTH_MONTH_POINT;
$results['add_point'] += $results['birth_point'];
if($results['add_point'] < 0) {
$results['add_point'] = 0;
* カートが保持するキー(商品種別ID)を配列で返す.
* @return array 商品種別IDの配列
foreach ($keys as $key) {
* カートに設定された現在のキー(商品種別ID)を登録する.
* @param integer $key 商品種別ID
$_SESSION['cartKey'] = $key;
* カートに設定された現在のキー(商品種別ID)を削除する.
unset ($_SESSION['cartKey']);
* カートに設定された現在のキー(商品種別ID)を取得する.
return $_SESSION['cartKey'];
* @return boolean カートが複数配送扱いの場合 true
* 引数の商品種別の商品がカートに含まれるかどうか.
* @param integer $product_type_id 商品種別ID
* @return boolean 指定の商品種別がカートに含まれる場合 true
Documentation generated on Fri, 24 Feb 2012 14:02:25 +0900 by Seasoft
|